package com.problem.leetcode;


/**
 * 解法，将奇数 偶数当做两个数组 分别遍历
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-12 12:39
 **/

public class Problem922 {
    public int[] sortArrayByParityII(int[] A) {
        int oddIndex = 1;
        for (int evenIndex = 0; evenIndex < A.length - 1; evenIndex = evenIndex + 2) {
            if ((A[evenIndex] & 1) != 0) {
                while ((A[oddIndex] & 1) != 0) {
                    oddIndex = oddIndex + 2;
                }
                int tmp = A[evenIndex];
                A[evenIndex] = A[oddIndex];
                A[oddIndex] = tmp;
            }
        }
        return A;
    }
}
